package main

import (
	"fmt"
	"im/rabbitmq"
	"time"
)

func main() {
	// r := rabbitmq.Ribbt{
	// 	TyMode:   "topic",
	// 	ExName:   "msg",
	// 	Qname:    "point",
	// 	RouteKey: "point",
	// 	Url:      "amqp://guest:guest@localhost:5672/",
	// }
	// r.GetRabbit()
	// r.CreateExTopic("")
	// rabbitmq.GetRabbitInstanse(&r)
	// fmt.Println(rabbitmq.RabbitIns)
	// for   {
	// 	msgs,_ := rabbitmq.RabbitIns.Customer("")
	// 	for v := range msgs {
	// 		fmt.Println(string(v.Body))
	// 		v.Ack(false)
	// 	}
	// 	time.Sleep(500 * time.Microsecond)
	// }

	client()
	select {

	}
}

func client() {
	rabbitmq.RabbitPoolServe = &rabbitmq.RabbitPool{
		AMQPURL:       "amqp://guest:guest@localhost:5672/",
		ConnectionNum: 5,
		ChannelNum:    1,
	}
	rabbitmq.RabbitPoolServe.InitRabbit()
	go func() {
		pools := make([]*rabbitmq.Pool, 5)
		for i:=0; i<5; i++ {
			pool,_ := rabbitmq.RabbitPoolServe.GetPool()
			pool.CreateExTopic("msg","point")
			pool.CreateQueuen("point")
			pools[i] = pool
		}
		for _,v := range pools {
			msgs, _ := v.CreateCustmer("")
			for v := range msgs {
				fmt.Println("收到消息: ", string(v.Body))
				v.Ack(false)
			}
			time.Sleep(500 * time.Microsecond)
		}
	}()

}
